package com.bupt.godxian.charging;

import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import io.jsonwebtoken.security.Keys;
import org.springframework.context.annotation.Bean;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

import javax.crypto.SecretKey;
import java.util.Base64;

@SpringBootApplication
public class ChargingApplication {

    public static void main(String[] args) {

//// 生成符合 HS512 算法要求的密钥值
//        SecretKey secretKey = Keys.secretKeyFor(SignatureAlgorithm.HS512);
//
//// 将密钥值转换为字符串形式
//        String secret = Base64.getEncoder().encodeToString(secretKey.getEncoded());
//
//// 输出生成的密钥值
//        System.out.println("Secret Key: " + secret);

        SpringApplication.run(ChargingApplication.class, args);

    }
    @Bean
    public CorsFilter corsFilter() {
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        corsConfiguration.addAllowedOrigin("http://localhost:8083");
        corsConfiguration.addAllowedHeader("*"); // 允许Authorization请求头Authorization
        corsConfiguration.addAllowedMethod("*");
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", corsConfiguration);
        return new CorsFilter(source);
    }

}
